home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr25 / gnuplsrc.zip / DIALOGS.C next >
C/C++ Source or Header  |  1993-03-21  |  15KB  |  389 lines

  1. #ifdef INCRCSDATA
  2. static char RCSid[]="$Id: dialogs.c,v 1.2 1992/07/26 12:37:10 fearick Exp fearick $" ;
  3. #endif
  4.  
  5. /****************************************************************************
  6.  
  7.     PROGRAM: gnushell
  8.     
  9.     a shell for gnuplot to allow plotting on pm with minimum hassle
  10.  
  11.     MODULE:  dialogs.c  Dialog procedures for Gnushell 
  12.         
  13. ****************************************************************************/
  14.  
  15. /*
  16.     Copyright (c) 1992, Roger Fearick.
  17.     All rights reserved
  18.      
  19.     THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT WARRANTIES OF ANY KIND. 
  20.    
  21.     Permission is hereby granted for personal, non-commercial use of this 
  22.     software.You are granted the right to use, modify, and redistribute 
  23.     it for for non-commercial purposes, provided that all copyright 
  24.     notices remain intact and all changes are clearly documented.      
  25.     THE AUTHOR MAKES NO WARRANTY OF ANY KIND WITH RESPECT TO THIS PRODUCT 
  26.     AND EXPLICITLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY 
  27.     OR FITNESS FOR ANY PARTICULAR PURPOSE.                               
  28. */
  29.  
  30. /* Update Log
  31. **
  32.  * $Log: dialogs.c,v $
  33.  * Revision 1.2  1992/07/26  12:37:10  fearick
  34.  * Initial 32-bit version
  35.  *
  36.  * Revision 1.1  1992/07/25  15:44:12  fearick
  37.  * Initial revision
  38.  *
  39.  *
  40. */ 
  41.  
  42. #define INCL_PM
  43. #define INCL_WIN
  44. #define INCL_DEV
  45. #define INCL_WINDIALOGS
  46. #define INCL_WINBUTTONS
  47. #define INCL_WINSYS
  48. #define INCL_WINFRAMEMGR
  49. #define INCL_WINPOINTERS
  50. #define INCL_WINTRACKRECT
  51. #define INCL_WINENTRYFIELDS
  52. #define INCL_WINWINDOWMGR
  53. #include <os2.h>
  54. #include <math.h>
  55. #include <stdio.h>
  56. #include <stdlib.h>
  57. #include <string.h>
  58. #include "gnushell.h"
  59.  
  60. static FONTMETRICS *afm = NULL ;  /* points to list of available fonts */
  61. static long QFonts( HWND ) ;
  62.  
  63. MRESULT EXPENTRY PrintDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
  64. /*
  65. **  print dialog box
  66. */
  67.     {
  68.     static idButton = 0 ;
  69.     static short shCaps = 0 ;
  70.     static char *szName ;
  71.     ULONG  ulStyle ;
  72.             
  73.     switch ( usMsg ) {
  74.  
  75.         case WM_INITDLG :
  76.         
  77.             szName = (char *) PVOIDFROMMP( mp2 ) ;
  78.             shCaps = QueryPrinterCaps( hwnd ) ;
  79.             if( shCaps & QP_CAPS_FILE ) {
  80.                 ulStyle = WinQueryWindowULong( WinWindowFromID( hwnd, IDD_PRINTQNAME ),
  81.                                                QWL_STYLE ) ;
  82.                 WinSetWindowULong( WinWindowFromID( hwnd, IDD_PRINTQNAME ),
  83.                                    QWL_STYLE, ulStyle ^ DT_HALFTONE  ) ;
  84.                 }
  85.             else {
  86.                 WinSendMsg( WinWindowFromID( hwnd, IDD_QPRNAME ),
  87.                             EM_SETREADONLY, TRUE, 0L ) ;
  88.                 }
  89.             WinSendMsg ( WinWindowFromID ( hwnd , IDD_PRINTPIC ) ,
  90.                          BM_CLICK ,  TRUE, NULL ) ;
  91.  
  92.             break ;
  93.             
  94.         case WM_COMMAND :
  95.  
  96.             switch ( (SHORT) mp1 ) {
  97.  
  98.                 case DID_OK:
  99.                     if( shCaps & QP_CAPS_FILE )
  100.                         WinQueryDlgItemText( hwnd, IDD_QPRNAME, 32, szName ) ;
  101.                     else 
  102.                         szName[0] = 0 ;
  103.                     WinDismissDlg( hwnd, idButton ) ;
  104.                     return 0L ;
  105.  
  106.                 case IDD_PRINTSETUP:
  107.                     SetupPrinter( hwnd ) ;
  108.                     return 0L ;
  109.  
  110.                 default:
  111.                     break ;
  112.                 }
  113.                 
  114.         case WM_CONTROL :
  115.  
  116.             switch ( SHORT1FROMMP ( mp1 ) ) {
  117.  
  118.                 case IDD_PRINTPIC:
  119.                     if( SHORT2FROMMP( mp1 ) == BN_CLICKED ) {
  120.                         idButton = SHORT1FROMMP ( mp1 ) - IDD_PRINTPIC + IDM_PRINTPIC ;
  121.                         return NULL ;
  122.                         }
  123.                     break ;
  124.                     
  125.                 default: break ;
  126.  
  127.                 }
  128.             break ;
  129.                     
  130.          default:
  131.             break ;
  132.             }
  133.         /* fall through to the default control processing */
  134.  
  135.     return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
  136.     }
  137.  
  138.  
  139. static struct { 
  140.     long    lTech ;     // printer technology
  141.     long    lVer ;      // driver version
  142.     long    lWidth ;    // page width in pels
  143.     long    lHeight ;   // page height in pels
  144.     long    lWChars ;   // page width in chars    
  145.     long    lHChars ;   // page height in chars    
  146.     long    lHorRes ;   // horizontal resolution pels / metre
  147.     long    lVertRes ;  // vertical resolution pels / metre
  148.     } prCaps ;
  149.  
  150. MRESULT EXPENTRY QPrintDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
  151. /*
  152. **  Query print area and printer setup
  153. */
  154.     {
  155.     static PQPRINT pqp = NULL ;
  156.     TRACKINFO ti ;
  157.     RECTL     rectlBox ;
  158.     static SWP swp ;    
  159.     HDC hdc ;
  160.  
  161.     switch ( usMsg ) {
  162.  
  163.         case WM_INITDLG :
  164.         
  165.             pqp = (PQPRINT) PVOIDFROMMP( mp2 ) ;
  166.  
  167.         case WM_USER_SET_DATA :
  168.  
  169.             WinSetDlgItemFloatF( hwnd, IDD_QPRXSIZE, 1, pqp->xsize ) ;
  170.             WinSetDlgItemFloatF( hwnd, IDD_QPRYSIZE, 1, pqp->ysize ) ;
  171.             WinSetDlgItemFloat( hwnd, IDD_QPRXFRAC, pqp->xfrac ) ;
  172.             WinSetDlgItemFloat( hwnd, IDD_QPRYFRAC, pqp->yfrac ) ;
  173.             WinQueryWindowRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
  174.                                 &rectlBox ) ;
  175.             WinQueryWindowPos( WinWindowFromID( hwnd, IDD_QPRBOX ),
  176.                                &swp ) ;
  177.             rectlBox.xRight = rectlBox.yTop * pqp->xsize/pqp->ysize ;
  178.             WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRBOX ),
  179.                              NULL, 0, 0, (short) rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE ) ;
  180.             rectlBox.xRight *= pqp->xfrac ;
  181.             rectlBox.yTop *= pqp->yfrac ;
  182.             WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRFRAME ),
  183.                              NULL, 
  184.                              swp.x, swp.y, //+(short)(swp.cy*(1.0-pqp->yfrac)),
  185.                              (short)rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE|SWP_MOVE ) ;
  186.             if( pqp->caps & QP_CAPS_FILE ) {
  187.                 ;
  188.                 }
  189.             else {
  190.                 WinSendMsg( WinWindowFromID( hwnd, IDD_QPRNAME ),
  191.                             EM_SETREADONLY, TRUE, 0L ) ;
  192.                 }
  193.             break ;
  194.             
  195.         case WM_COMMAND :
  196.  
  197.             switch ( (SHORT) mp1 ) {
  198.  
  199.                 case DID_OK:
  200.                     WinQueryDlgItemFloat( hwnd, IDD_QPRXFRAC, &pqp->xfrac ) ;
  201.                     WinQueryDlgItemFloat( hwnd, IDD_QPRYFRAC, &pqp->yfrac ) ;
  202.  
  203.                     if( pqp->caps & QP_CAPS_FILE ) {
  204.                         WinQueryDlgItemText( hwnd, IDD_QPRNAME, 16, pqp->name ) ;
  205.                         }
  206.                     break ;
  207.  
  208.                 case IDD_QPRSETPR:   /* printer setup */
  209.                     SetPrinterMode( hwnd ) ;
  210.                     if( (hdc = OpenPrinterDC( WinQueryAnchorBlock( hwnd ), OD_INFO, NULL )) != DEV_ERROR ) {
  211.                         DevQueryCaps( hdc, CAPS_TECHNOLOGY, (long)sizeof(prCaps)/sizeof(long), (PLONG)&prCaps ) ;
  212.                         DevCloseDC( hdc ) ;
  213.                         pqp->xsize = (float)100.0* (float) prCaps.lWidth / (float) prCaps.lHorRes ; // in cm
  214.                         pqp->ysize = (float)100.0* (float) prCaps.lHeight / (float) prCaps.lVertRes ; // in cm
  215.                         WinSendMsg( hwnd, WM_USER_SET_DATA, 0L, 0L ) ;
  216.                         }
  217.                     return 0L ;
  218.  
  219.                 case IDD_QPRTRACK :     /* track plot area */
  220.                     WinQueryWindowRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
  221.                                         &rectlBox ) ;
  222.                     ti.cxBorder = ti.cyBorder = 2 ;
  223.                     ti.cxGrid = ti.cyGrid = 0 ;
  224.                     ti.cxKeyboard = ti.cyKeyboard = 2 ;
  225.                     ti.ptlMinTrackSize.x = ti.ptlMinTrackSize.y = 2 ;
  226.                     ti.rclBoundary = rectlBox ;
  227.                     ti.ptlMaxTrackSize.x = rectlBox.xRight ;
  228.                     ti.ptlMaxTrackSize.y = rectlBox.yTop ;
  229.                     ti.rclTrack.xRight = pqp->xfrac * rectlBox.xRight ;
  230.                     ti.rclTrack.yTop = pqp->yfrac*rectlBox.yTop ;
  231.                     ti.rclTrack.xLeft = 0 ;
  232.                     ti.rclTrack.yBottom = 0 ;//(1.0-pqp->yfrac) * rectlBox.yTop ;
  233.                     ti.fs = TF_RIGHT|TF_TOP|TF_STANDARD|TF_SETPOINTERPOS|TF_ALLINBOUNDARY ;
  234.                     WinSetPointer( HWND_DESKTOP, 
  235.                                    WinQuerySysPointer( HWND_DESKTOP, SPTR_SIZENWSE, FALSE ) ) ;
  236.                     WinTrackRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
  237.                                   NULL, 
  238.                                   &ti ) ;
  239.                     pqp->xfrac = (float)ti.rclTrack.xRight / (float)rectlBox.xRight ;
  240.                     pqp->yfrac = ((float)(ti.rclTrack.yTop-ti.rclTrack.yBottom) / (float)rectlBox.yTop) ;
  241.                     rectlBox.yTop = ti.rclTrack.yTop - ti.rclTrack.yBottom ;
  242.                     rectlBox.xRight = ti.rclTrack.xRight ;
  243.                     WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRFRAME ),
  244.                                      NULL, 
  245.                                      swp.x, swp.y,//+(short)(swp.cy*(1.0-pqp->yfrac)),
  246.                                      (short)rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE|SWP_MOVE ) ;
  247.                     WinSetDlgItemFloat( hwnd, IDD_QPRXFRAC, pqp->xfrac ) ;
  248.                     WinSetDlgItemFloat( hwnd, IDD_QPRYFRAC, pqp->yfrac ) ;
  249.                     return 0L ;
  250.                     
  251.                 default:
  252.                     break ;
  253.                 }
  254.                 
  255.          default:
  256.             break ;
  257.             }
  258.         /* fall through to the default control processing */
  259.  
  260.     return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
  261.     }
  262.  
  263.  
  264. MRESULT EXPENTRY QFontDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  265. /*
  266. ** query font dialog function
  267. */
  268.     {
  269.     extern HWND hApp ;
  270.     HWND   hwndEx ;
  271.     HPS    hps ;
  272.     short  sCount, i ;
  273.     static HWND hwndLB ;  // listbox handle
  274.     static long lCount = 0L ;           // number of fonts found
  275.     static short shSize = 10 ;          // point size of current selection
  276.     static char  szFontName[50] ;       // name of current font
  277.     static char  szFontNameSize[50] ;   // current font size&name combo
  278.     static char *pszFontNameSize ;
  279.     ULONG usItem ;
  280.  
  281.     switch (msg) {
  282.  
  283.         case WM_INITDLG:
  284.         
  285.             pszFontNameSize = (PSZ) PVOIDFROMMP( mp2 ) ;
  286.             if( pszFontNameSize != NULL )
  287.                 sscanf( pszFontNameSize, "%d", &shSize ) ;
  288.             WinSetDlgItemShort( hwnd, IDD_FONTSIZE, shSize, FALSE ) ;
  289.             hwndLB = WinWindowFromID( hwnd, IDD_HLIST ) ;
  290.             if( afm == NULL ) lCount = QFonts( hApp ) ;
  291.             sCount = (short) lCount ;
  292.             for( i=0; i<sCount;i++ ) {
  293.                 if( afm[i].fsDefn & FM_DEFN_OUTLINE ) { 
  294.                     WinSendMsg( hwndLB,
  295.                                LM_INSERTITEM,
  296.                                LIT_END,
  297.                                MPFROMP((PSZ)afm[i].szFacename) ) ;
  298.                     }
  299.                 } 
  300.                 
  301.             WinSendMsg( hwndLB,
  302.                         LM_SELECTITEM,
  303.                         MPFROMSHORT( 0 ),
  304.                         TRUE ) ;
  305.        
  306.             break ;
  307.  
  308.         case WM_USER_CHGFONT:
  309.         
  310.             sprintf( szFontNameSize,
  311.                      "%d.%s",
  312.                      shSize,
  313.                      szFontName ) ;
  314.             hwndEx = WinWindowFromID( hwnd, IDD_FONTEX ) ;
  315. //            hps = WinGetPS( hwndEx ) ;
  316.             WinSetPresParam(hwndEx, 
  317.                             PP_FONTNAMESIZE,
  318.                             (ULONG)sizeof(szFontNameSize),
  319.                             szFontNameSize ) ;
  320. //            WinReleasePS( hps ) ;
  321.             return 0L ;
  322.             
  323.         case WM_CONTROL:
  324.         
  325.             if( SHORT1FROMMP( mp1 ) == IDD_HLIST ) {
  326.                 if( SHORT2FROMMP( mp1 ) == LN_SELECT  ) {
  327.                     usItem = (ULONG)WinSendMsg( hwndLB,
  328.                                 LM_QUERYSELECTION,
  329.                                 0L,
  330.                                 0L ) ;
  331.                     WinSendMsg( hwndLB,
  332.                                 LM_QUERYITEMTEXT,
  333.                                 MPFROM2SHORT( usItem, 50 ),
  334.                                 MPFROMP((PSZ)szFontName) ) ;
  335.                     WinQueryDlgItemShort( hwnd, IDD_FONTSIZE, &shSize, FALSE ) ;
  336.                     if( shSize != 0 ) WinSendMsg( hwnd, WM_USER_CHGFONT, 0L, 0L ) ;
  337.                     }
  338.                 }
  339.             else if( SHORT1FROMMP( mp1 ) == IDD_FONTSIZE ) {
  340.                 if( SHORT2FROMMP( mp1 ) == EN_CHANGE  ) {
  341.                     WinQueryDlgItemShort( hwnd, IDD_FONTSIZE, &shSize, FALSE ) ;
  342.                     if( shSize != 0 ) WinSendMsg( hwnd, WM_USER_CHGFONT, 0L, 0L ) ;
  343.                     }
  344.                 }
  345.             break ;
  346.  
  347.         case WM_COMMAND:
  348.             if (SHORT1FROMMP(mp1) == DID_OK) {
  349.                 strcpy( pszFontNameSize, szFontNameSize ) ;
  350.                 WinDismissDlg( hwnd, DID_OK );
  351.                 return 0L;
  352.                 }
  353.             break;
  354.         }
  355.     return WinDefDlgProc( hwnd, msg, mp1, mp2 ) ;
  356.     }
  357.  
  358.  
  359. static long QFonts( HWND hwnd )
  360. /*
  361. **  Get list of available fonts
  362. */
  363.     {
  364.     FONTMETRICS fm;
  365.     LONG lCount, lFontCount;
  366.     HPS hps;
  367.  
  368.     hps = WinGetPS( hwnd ) ;
  369.     lCount = 0 ;
  370.     lFontCount = GpiQueryFonts(hps,
  371.                                QF_PUBLIC,
  372.                                NULL,   /* queries all public fonts */
  373.                                &lCount,
  374.                                (LONG) (sizeof(fm)),
  375.                                (PFONTMETRICS) &fm);
  376.     lCount = lFontCount ; 
  377.     afm = malloc( lCount*sizeof(FONTMETRICS) ) ;
  378.     lFontCount = (long) GpiQueryFonts(hps,
  379.                                QF_PUBLIC,
  380.                                NULL,   /* queries all public fonts */
  381.                                &lCount,
  382.                                (LONG) (sizeof(fm)),
  383.                                (PFONTMETRICS) afm);
  384.     WinReleasePS( hwnd ) ;
  385.     return lCount ;
  386.     }
  387.  
  388.  
  389.